

import { defHttp } from "/@/utils/http/axios/nss";
import { useUserStore } from "/@/store/modules/user";
const store = useUserStore()
enum Api {
	// /flow/node/list
	list = '/system/flow/flowRecord/list',// 流程记录分页列表查询 POST
	save = '/system/flow/flowRecode/saveOrUpdate',//  流程记录新增/修改  POST
	delete = '/system/flow/flowRecord/remove ', //  流程记录删除 POST 
	get = '/system/flow/flowRecord/detail',  // POST  流程记录查看详情 根据id查询
	getNodeById = '/system/flow/node/detail',  // POST /{id} 工作流-流程节点查看详情 根据nodeId查询
}

/**
 * 查询列表
 * @param params
 */
export const getFlowRecordList = async (params) => {
	console.log('params', params);

	const data = {
		query: [
			{ flowName: params.flowName },
			{ keyWords: params.keyWords },
			{ handleUser: store.userInfo.userId ? store.userInfo.userId : '' }
		],
		page: {
			current: params.pageNo,
			size: params.pageSize
		}
	}
	const { records } = await defHttp.post({ url: Api.list, data });
	return records;
};

/**
 * 新增/修改流程记录
 * @param params
 */
export const saveOrUpdateFlowRecord = (params) => {
	return defHttp.post({ url: Api.save, params });
};

/**
 * 删除流程记录
 * @param id 记录主键ID
 * @param handleSuccess 删除成功后的回调（可选）
 */
export const deleteFlowRecordById = (id, handleSuccess) => {
	const url = Api.delete.replace(/\s+/g, ''); // 移除空格
	return defHttp.post({ url: `${url}/${id}` }, { joinParamsToUrl: true }).then(() => {
		if (handleSuccess instanceof Function) {
			handleSuccess();
		}
	});
};

/**
 * 获取指定 ID 的流程记录详情
 * @param id 记录主键ID
 */
export const getFlowRecordDetailById = (id) => {
	return defHttp.post({ url: Api.get, params: { id } });
};


/**
 * 获取指定 ID 的流程记录详情
 * @param id 记录主键ID
 */
export const getNodeById = (id) => {
	const url = Api.getNodeById.replace(/\s+/g, ''); // 移除空格
	return defHttp.post({ url: `${url}/${id}` });
};
